package org.example.springbootwebexample.controller;


import lombok.extern.slf4j.Slf4j;
import org.example.springbootwebexample.pojo.Dept;
import org.example.springbootwebexample.pojo.Result;
import org.example.springbootwebexample.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j    //酸辣粉,日志记录器
@RestController
@RequestMapping("/depts")
public class DeptController {


   // private static Logger log = LoggerFactory.getLogger(DeptController.class);  //声明日志记录器


    @Autowired
    private DeptService deptService;

    //@RequestMapping(value = "/depts",method = RequestMethod.GET)

    @GetMapping
    public Result list(){

        log.info("查询全部的部门Date");

        List<Dept> deptList =  deptService.list();

        return Result.success(deptList);
    }


    @DeleteMapping(value = "/{id}")
    public Result delete(@PathVariable Integer id){

        log.info("根据id删除部门，ID: {}",id);
        deptService.delete(id);
        return Result.success();

    }


    @PostMapping
    public Result add(@RequestBody Dept dept){

        log.info("新增部门 {}" ,dept.getName());
        deptService.add(dept);
        return Result.success();

    }



}
